<template>
  <a-modal title="导出用户数据" style="top: 100px;" :visible="isShow" width="600px" @ok="handleOk" @cancel="handleCancel"
    okText="确认导出">
    <IForm :formFrame="frame" class="form-container" :formData.sync="form"></IForm>
    共查询到 {{itemTotal}} 个用户
  </a-modal>
</template>
<script>
  import {
    mapGetters
  } from 'vuex'
  import {
    ACCESS_TOKEN
  } from '@/store/mutation-types'
  import IForm from "@/components/IForm"

  export default {
    components: {
      IForm
    },
    props: {
      isShow: {
        type: Boolean
      }
    },
    computed: {
      ...mapGetters(['baseUrl']),
      uploadUrl() {
        return `${this.baseUrl}/admin-api/batch-deliver`
      },
      frame() {
        return [
          {
            title: '用户类型',
            key: 'type',
            type: 'radio',
            default: 'wechat',
            required: true,
            span: 24,
            options: [{
              title: '微信',
              value: 'wechat'
            },
            {
              title: '微信广告',
              value: 'adq'
            }
            ],
            tips: ''
          },
          {
            title: '注册时间(始)',
            key: 'created_start_at',
            type: 'date',
            showTime: false,
            required: true,
          },
          {
            title: '注册时间(结束)',
            key: 'created_end_at',
            type: 'date',
            showTime: false,
            required: true,
          },
          {
            type: 'number',
            key: "per_page",
            title: "每页条数",
            default: 2000,
          },
          {
            type: 'number',
            key: "page",
            title: "要导出的页码",
            tips: '填5则导出第5页',
            default: 1
          },
        ]
      }
    },
    data() {
      return {
        form: {
          abc: "abc"
        },
        itemTotal: 0
      }
    },
    watch: {
      form: {
        handler(new_value, old_value) {
          // this.$http.post('/export/user-total', this.form).then(res => {
          //   this.itemTotal = res.data.total
          // })
        },
        deep: true
      }
    },
    mounted () {

    },
    methods: {
      handleChange({
        file,
        fileList
      }) {},
      handleOk() {
        this.$http.post('/export/users', {
          ...this.form
        }).then(res => {
          const tempwindow = window.open()
          tempwindow.location = process.env.VUE_APP_BASE_URL + `${res.data.url}`
          // window.open(process.env.VUE_APP_BASE_URL + `/${res.data.url}`, '_blank')
        }).finally(() => {})
      },
      handleCancel() {
        this.$emit('hide')
      }
    }
  }
</script>
<style lang="scss" scoped>
  .tips {
    color: gray;
    font-size: 80%;
  }
</style>
